package com.hdu.pyl.service.basic;

import com.hdu.pyl.mappper.UserMapper;
import com.hdu.pyl.mappper.UserTagsMapper;
import com.hdu.pyl.pojo.User;
import com.hdu.pyl.pojo.UserTags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserTagsMapper userTagsMapper;

    @Override
    public User createUser(User user) {
        if (user == null || user.getName() == null) {
            return null;
        }
        try {
            userMapper.inserUser(user);
            return user;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public User insertUser(User user) {
        if (user == null || user.getName() == null) {
            return null;
        }
        try {
            userMapper.inserUser(user);
            UserTags userTags = user.getUserTags();
            userTags.setUserId(user.getId());
            userTagsMapper.insertUserTag(userTags);
            return user;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public User findUserById(Integer userId) {
        return userMapper.findUserById(userId);
    }
}
